import tarfile
import argparse

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description='转码gb2312到utf8')
    parser.add_argument('-f', action='store', help='输出文件名', required=True)
    parser.add_argument('-d', action='store', help='压缩的目录', required=True)    
    try:
        results = parser.parse_args()
        print(results)

        dirname = results.d
        
        filename = results.f

        with tarfile.open(filename+".tar", mode="w") as out:
            out.add(dirname)

    except Exception as e:
        print(e)
        parser.print_help()
